<?php
/**
 *
 * @Author nikm $
 *
 * @Date 2012-05-01 $
 */

if(!defined('FROM_INDEX')) exit('Invalid request');

require ROOT_PATH.'module/ajax/master.mod.php';
require_once ROOT_PATH.'include/lib/image.func.php';

class moduleObj extends masterObj
{
	function __construct($request)
	{
		parent::__construct($request);

		$this->excute();
	}

	function excute()
	{
		switch($this->act)
		{
			case 'check_name':
				$this->checkName();
				break;
			default:
				exit();
		}
	}

	private function checkName()
	{
		$name = isset($this->request['name']) ? trim($this->request['name']) : '';
		$type = isset($this->request['type']) ? trim($this->request['type']) : '';
		
		if(!$name)
		{
			$this->jsonMessage('请输入名称', 'OK');
		}

		$info_b = get_business(array('name'=>$name));
		$info_h = get_hostel_info(array('name'=>$name));
		$info_t = get_travel_item(array('name'=>$name));
		
		if(!isset($info_b['id']) && !isset($info_h['id']) && isset($info_t['id'])) $this->jsonMessage("该名称已被使用", 'NO');
		
		$info = array();
		if($type == 'business')
		{
			if(isset($info_b['id'])) $this->jsonMessage("商家已存在，请不要重复添加", 'NO');
			if(isset($info_h['id'])) $info = $info_t;
		}
		else if($type == 'hostel')
		{
			if(isset($info_h['id'])) $this->jsonMessage("商家已存在，请不要重复添加", 'NO');
			if(isset($info_b['id'])) $info = $info_t;
		}
		unset($info_b);
		unset($info_h);
		unset($info_t);
		
		if(!isset($info['id']) || $info['id'] < 1)
		{
			$this->jsonMessage("该名称不存在", 'NO');
		}
		
		$this->jsonResponse($info);
	}
}